<!DOCTYPE html>
<html>
  
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  <meta name="author" content="Aa Y">
  
  
  <title>GomokuAI重置企划1 | Yaa&#39;s Bolg</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="GomokuAI重置企划,五子棋,">
  

  
  <meta name="description" content="咕价函数">

  

  
    <script src="//cdn.jsdelivr.net/npm/leancloud-storage@3.11.1/dist/av-min.js" async></script>
  

  

  
    <script src="//unpkg.com/valine/dist/Valine.min.js" async></script>
  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"fmmQ5HHXBeCLVf0DYXAfyBnM-gzGzoHsz","appkey":"WaRxtuWpVWcnAiqd2erlT4vy","comment":true,"count":true},
    welcome: {"enable":false,"interval":30},
    start_time: "2019-05-01",
    passwords: ["efe07af7441da2b69c4a41e42e73be4db47f66010a56900788a458354a7373ec", ],
    is_post: true,
    lock: false,
    author: "Aa Y",
    share: {"twitter":false,"facebook":false,"weibo":true,"qq":true,"wechat":true},
    mathjax: false,
    page_type: "",
    root: "/blog/"
  };
</script>

  <script src="/blog/vendor/sha256.min.js"></script>
<script src="/blog/js/auth.js"></script>
<script src="/blog/js/index.js"></script>
<script src="/blog/vendor/qrcode.min.js"></script>

  
    <link rel="icon" href="/blog/images/favicon.ico">
    <link rel="apple-touch-icon" href="/blog/images/touch-icon.png">
  

  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.css" rel="stylesheet">

  <link rel="stylesheet" href="/blog/css/index.css">
<link rel="stylesheet" href="/blog/styles/components/highlight/highlight.css">

  
</head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/blog/">Yaa</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | Blog</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/blog/" target="_self">首页</a>
      
        <a href="/blog/archives/" target="_self">归档</a>
      
        <a href="/blog/tags/" target="_self">标签</a>
      
        <a href="/blog/categories/" target="_self">分类</a>
      
        <a href="/blog/about/" target="_self">关于</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://github.com/zyayoung/" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/blog/" target="_self">
            首页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/about/" target="_self">
            关于
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2019-05-05
    </span>
    
      <span>
        | <a href="/blog/categories/GomokuAI重置企划/"><i class="fa fa-bookmark"></i>GomokuAI重置企划</a>
      </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
  </div>
  <h1 class="passage-title">
    GomokuAI重置企划1
  </h1>
  
  <article class="passage-article">
    <h2 id="xl-engine弱化版分析"><a class="markdownIt-Anchor" href="#xl-engine弱化版分析"></a> xl-engine弱化版分析</h2>
<p><a href="https://github.com/accreator/xl-engine" target="_blank" rel="noopener">xl-engine</a>主要提供如下思路：</p>
<ol>
<li>置换表</li>
<li>历史启发</li>
<li>alpha-beta 或 MTD(f)</li>
<li>增量式棋盘</li>
<li>增量式估值</li>
<li>真假禁手识别</li>
<li>VCF 扩展</li>
</ol>
<p>在弱化版中实现(chao)了3-6, 其中估值使用的是所有位置落子后能形成的棋形加权求和。</p>
<h2 id="第0步连续5格的估值表"><a class="markdownIt-Anchor" href="#第0步连续5格的估值表"></a> 第0步：连续5格的估值表</h2>
<p>对于五个连续空位（空或包含己方棋子）中<span class="katex"><span class="katex-mathml"><math><semantics><mrow><msup><mn>2</mn><mn>5</mn></msup></mrow><annotation encoding="application/x-tex">2^5</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:0.8141079999999999em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathrm">2</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathrm">5</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span></span></span></span>种情况，对每个位置落子后能形成的棋形估值。</p>
<p><a href="https://gitee.com/zyayoung/Gomoku/blob/c3891f5114ec1f3deff165d26f05b6a992e864c0/main.cpp" target="_blank" rel="noopener">Code</a></p>
<p>在ai.pattern5stone[p][i]存储了五个连续空位中所有情况p中位置i落子后能形成的棋形。其中p为7位二进制数，存储五个连续空位有无己方棋子以及两边有无遮挡。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">bool</span> AI::isP5(<span class="keyword">int</span> p) &#123; <span class="keyword">return</span> (p &amp; <span class="number">0B</span>0111110) == <span class="number">0B</span>0111110; &#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> AI::isP4(<span class="keyword">int</span> p) &#123;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>0111101 || p == <span class="number">0B</span>0111100) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>0011110 || p == <span class="number">0B</span>1011110) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>0111010 || p == <span class="number">0B</span>0101110) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>0110110) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> AI::isP4d(<span class="keyword">int</span> p) &#123;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1111101 || p == <span class="number">0B</span>1111100) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1011111 || p == <span class="number">0B</span>0011111) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1101110 || p == <span class="number">0B</span>0101111) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1101111) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1111010 || p == <span class="number">0B</span>0111011) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1111011) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>0110111 || p == <span class="number">0B</span>1110110) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">if</span> (p == <span class="number">0B</span>1110111) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> AI::isP3(<span class="keyword">int</span> p) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (isP4(p | <span class="number">1</span> &lt;&lt; i)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> AI::isP3d(<span class="keyword">int</span> p) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (isP4d(p | <span class="number">1</span> &lt;&lt; i)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> AI::isP2(<span class="keyword">int</span> p) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (isP3(p | <span class="number">1</span> &lt;&lt; i)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> AI::isP1(<span class="keyword">int</span> p) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= <span class="number">5</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (isP2(p | <span class="number">1</span> &lt;&lt; i)) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">void</span> AI::genPattern5Stone() &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; <span class="number">1</span> &lt;&lt; <span class="number">7</span>; j++) &#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> k = <span class="number">1</span>; k &lt;= <span class="number">5</span>; k++) &#123;</span><br><span class="line">            pattern5stone[j][k - <span class="number">1</span>] = P0;</span><br><span class="line">            <span class="keyword">if</span> (j &amp; <span class="number">1</span> &lt;&lt; k) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P0;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP5(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P5;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP4(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P4;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP4d(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P4d;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP3(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P3;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP3d(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P3d;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP2(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P2;</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (isP1(j | <span class="number">1</span> &lt;&lt; k)) &#123;</span><br><span class="line">                pattern5stone[j][k - <span class="number">1</span>] = P1;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="第1步单方向估值表"><a class="markdownIt-Anchor" href="#第1步单方向估值表"></a> 第1步：单方向估值表</h2>
<p>找到每个方向所有可能成五个子的空位，查表索引求和</p>
<p><a href="https://www.aiexp.info/files/introduction_to_xl.pdf" target="_blank" rel="noopener">xl文档</a>提供了很大的帮助：</p>
<ol>
<li>对于多余五个子的连续空间，可以使用大小为5的窗口滑动，对每个空位取最大值即可</li>
<li>对于长度为5-15的连续空间的所有情况可以预先计算完成</li>
</ol>
<p>生成所有长度的单方向估值表</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> AI::genPatternCache() &#123;</span><br><span class="line">    <span class="comment">// length &lt; 5</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> length = <span class="number">0</span>; length &lt; <span class="number">5</span>; length++) patternCache.push_back(&#123;&#123;&#125;&#125;);</span><br><span class="line">    <span class="comment">// length == 5</span></span><br><span class="line">    <span class="built_in">vector</span>&lt;<span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;&gt; patternCacheAtLength5;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> pattern = <span class="number">0</span>; pattern &lt; <span class="number">1</span> &lt;&lt; <span class="number">5</span>; pattern++) &#123;</span><br><span class="line">        <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; patternCacheAtPattern;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">            patternCacheAtPattern.push_back(pattern5stone[<span class="number">0B</span>1000001 | pattern &lt;&lt; <span class="number">1</span>][i]);</span><br><span class="line">        &#125;</span><br><span class="line">        patternCacheAtLength5.push_back(patternCacheAtPattern);</span><br><span class="line">    &#125;</span><br><span class="line">    patternCache.push_back(patternCacheAtLength5);</span><br><span class="line">    <span class="comment">// length &gt;= 5</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> length = <span class="number">6</span>; length &lt;= BOARD_SIZE; length++) &#123;</span><br><span class="line">        <span class="built_in">vector</span>&lt;<span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt;&gt; patternCacheAtLength;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> pattern = <span class="number">0</span>; pattern &lt; <span class="number">1</span> &lt;&lt; length; pattern++) &#123;</span><br><span class="line">            <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; patternCacheAtPattern(length, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">            <span class="comment">// left</span></span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++)</span><br><span class="line">                patternCacheAtPattern[i] = pattern5stone[(pattern &amp; <span class="number">0B</span>11111) &lt;&lt; <span class="number">1</span> | <span class="number">1</span>][i];</span><br><span class="line"></span><br><span class="line">            <span class="comment">// right</span></span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = length - <span class="number">5</span>; i &lt; length; i++)</span><br><span class="line">                patternCacheAtPattern[i] = max(</span><br><span class="line">                    patternCacheAtPattern[i],</span><br><span class="line">                    pattern5stone[(pattern &gt;&gt; (length - <span class="number">5</span>) &amp; <span class="number">0B</span>11111) &lt;&lt; <span class="number">1</span> | <span class="number">1</span> &lt;&lt; <span class="number">6</span>][i - length + <span class="number">5</span>]);</span><br><span class="line"></span><br><span class="line">            <span class="comment">// center</span></span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> from = <span class="number">1</span>, to = <span class="number">5</span>; to &lt; length - <span class="number">1</span>; from++, to++) &#123;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = from; i &lt;= to; i++)</span><br><span class="line">                    patternCacheAtPattern[i] = max(</span><br><span class="line">                        patternCacheAtPattern[i],</span><br><span class="line">                        pattern5stone[(pattern &gt;&gt; (from) &amp; <span class="number">0B</span>11111) &lt;&lt; <span class="number">1</span>][i - from]);</span><br><span class="line">            &#125;</span><br><span class="line">            patternCacheAtLength.push_back(patternCacheAtPattern);</span><br><span class="line">        &#125;</span><br><span class="line">        patternCache.push_back(patternCacheAtLength);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>生成当前棋盘的单方向估值表</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> AI::updatePMap(<span class="keyword">int</span> side) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> k = <span class="number">0</span>; k &lt; DIRS.size(); k++) &#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; DIRS_START[k].size(); j++) &#123;</span><br><span class="line">            <span class="keyword">int</span> p = <span class="number">0</span>;  <span class="comment">// p - Pattern 0B00000</span></span><br><span class="line">            <span class="keyword">int</span> len = <span class="number">0</span>;</span><br><span class="line">            Position pos = DIRS_START[k][j];</span><br><span class="line">            <span class="keyword">for</span> (; pos.isValid(); pos += DIRS[k]) &#123;</span><br><span class="line">                <span class="keyword">if</span>(board[pos.x][pos.y] == side)</span><br><span class="line">                    p = p&lt;&lt;<span class="number">1</span> | <span class="number">1</span>, len++;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (board[pos.x][pos.y] == EMPTY)</span><br><span class="line">                    p = p &lt;&lt; <span class="number">1</span>, len++;</span><br><span class="line">                <span class="keyword">else</span>&#123;</span><br><span class="line">                    <span class="keyword">if</span> (len &gt;= <span class="number">5</span>) &#123;</span><br><span class="line">                        Position tmpPos = pos;</span><br><span class="line">                        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; len; i++) &#123;</span><br><span class="line">                            tmpPos += -DIRS[k];</span><br><span class="line">                            assert(tmpPos.isValid());</span><br><span class="line">                            PMap[tmpPos.x][tmpPos.y][k][side] = patternCache[len][p][i];</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                    len = p = <span class="number">0</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (len &gt;= <span class="number">5</span>) &#123;</span><br><span class="line">                Position tmpPos = pos;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; len; i++) &#123;</span><br><span class="line">                    tmpPos += -DIRS[k];</span><br><span class="line">                    PMap[tmpPos.x][tmpPos.y][k][side] = patternCache[len][p][i];</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Update PnCount</span></span><br><span class="line">    <span class="built_in">memset</span>(PnCount, <span class="number">0</span>, <span class="keyword">sizeof</span>(PnCount));</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; BOARD_SIZE; i++) &#123;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>; j&lt;BOARD_SIZE; j++)&#123;</span><br><span class="line">            <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>; k&lt;<span class="number">4</span>; k++)&#123;</span><br><span class="line">                PnCount[PMap[i][j][k][side]][side]++;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="未来的工作多方向估值表-增量式估值"><a class="markdownIt-Anchor" href="#未来的工作多方向估值表-增量式估值"></a> 未来的工作：多方向估值表、增量式估值</h2>
<p>多方向<br>
局部更新</p>
  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#xl-engine弱化版分析"><span class="toc-text"> xl-engine弱化版分析</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第0步连续5格的估值表"><span class="toc-text"> 第0步：连续5格的估值表</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#第1步单方向估值表"><span class="toc-text"> 第1步：单方向估值表</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#未来的工作多方向估值表-增量式估值"><span class="toc-text"> 未来的工作：多方向估值表、增量式估值</span></a></li></ol>
  </div>
</aside>
  
    <aside class="passage-copyright">
      <div>本文作者: Yaa</div>
      
        <div>
          原文链接: 
          <a href="" target="_blank">http://zyayoung.gitee.io/blog/passages/GomokuAI重置企划1/</a>
        </div>
      
      <div>
        转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/blog/tags/五子棋/"><i class="fa fa-tags"></i>五子棋</a>
    
    </div>
  
</div>

    </main>
    
      
<div class="site-comment-contanier" data-plateform="leancloud">
  
    <p id="site-comment-info">
      <i class="fa fa-spinner fa-spin"></i> 评论加载中
    </p>
    <div id="site-comment"></div>
  
</div>
    
    <div class="site-footer-wrapper">
  <footer class="site-footer">
    
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">博客推荐</h5>
          
            <span class="site-footer-item">
              <a href="https://scarlet-climax.github.io/" target="_blank">Scarlet Devil Mansion</a>
            </span>
          
        </div>
      
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
      <div class="site-footer-info">
        <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
      </div>
    
    
      <div class="site-footer-info">
        <i class="fa fa-at"></i> Email: 1328410180@qq.com
      </div>
    
    <div class="site-footer-info">
      <i class="fa fa-copyright"></i> 
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div>
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">
  <div class="bottom-bar-left">
    <a href="/blog/passages/OpenGL导入3D模型/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/blog/passages/GomokuAI重置企划0/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
    <a id="share-btn-weibo" href="javascript:void(0);" target="_blank">
      <i class="fa fa-weibo"></i>
    </a>
  
  
    <a id="share-btn-qq" href="javascript:void(0);" target="_blank">
      <i class="fa fa-qq"></i>
    </a>
  
  
    <a id="share-btn-wechat" href="javascript:void(0);" target="_blank">
      <i class="fa fa-wechat"></i>
    </a>
  
</div>
    





    
  </body>
</html>